import Cookie from "js-cookie"
import router from "../../router/index.js"
//import router from "../../router"
export default{
    state:{
        isCollapse:false,
        tabsList :[
            {
                path: '/home',
                name: "home",
                label: "首页",
                icon: "home"
            }
        ],
        currentMenu:null,
        menu:[],
        menuArray:[]
    },
    mutations:{
        collapseMenu(state){
            state.isCollapse = !state.isCollapse
        },
        selectMenu(state,val){
            if(val.name !== "home"){
                state.currentMenu = val
                const result = state.tabsList.findIndex(item => item.name === val.name)
                if(result === -1){
                    state.tabsList.push(val)
                }
            } else {
                state.currentMenu = null
            }
        },
        // setMenu(state,val){
        //     state.menu = val
        //     Cookie.set('menu' , JSON.stringify(val))

        // },
        // clearMenu(state){
        //     state.menu = []
        //     Cookie.remove('menu')
        // },
        // addMenu(state,router){
        //     if(!Cookie.get('menu')){
        //         return
        //     }
        //     const menu = JSON.parse(Cookie.get('menu'))
        //     state.menu = menu
            
        //     state.menu.forEach(item => {
                
        //         if(item.children){
        //             item.children = item.children.map(item => {
        //                 item.component = () => import(`../../view/${item.url}`)
        //                 return item
        //             })
        //             state.menuArray.push(...item.children)
        //         }else{
        //             item.component = () => import(`../../view/${item.url}`)
        //             state.menuArray.push(item)
        //         }
        //     });
        //     //路由的动态添加
            
        //     state.menuArray.forEach(item =>{
        //         router.addRoutes('Main',item)
        //     })
        // }
    }
}